import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

/**
 * @author fangjiaxiaobai@gmail.com
 * @date 2020-05-13
 * @since 1.0.0
 */
public class OtherTest {

    public static void main(String[] args) {
        List<Stat> list = new LinkedList<>();
        list.add(new Stat("2020-04-22", 1, 1));
        list.add(new Stat("2020-04-22", 2, 2));
        list.add(new Stat("2020-04-23", 1, 1));

        List<Stat> mergedList = mergeList(list);

        System.out.println(mergedList);
//        mergedList中的元素为：
//        Stat("2020-04-22", 3, 3)
//        Stat("2020-04-23", 1, 1)
    }


    private static List<Stat> mergeList(List<Stat> list) {
        LinkedList<Stat> mergeLists = new LinkedList<>();

        int j = 0;
        for (int i = 0; i < list.size(); i++) {
            Stat item = list.get(i);

            if(j == 0) {
                mergeLists.add(item);
                j++;
            }else {
                Stat mergeItem = mergeLists.get(j-1);
                if (mergeItem.getDate().equals(item.getDate())) {
                    mergeItem.setActiveCount(mergeItem.getActiveCount() + item.getActiveCount());
                    mergeItem.setRegisterCount(mergeItem.getRegisterCount() + item.getRegisterCount());
                } else {
                    mergeLists.add(item);
                    j++;
                }
            }
        }

        return mergeLists;

    }
}

class Stat {


    public Stat(String date, int registerCount, int activeCount) {
        super();
        this.date = date;
        this.registerCount = registerCount;
        this.activeCount = activeCount;
    }

    private String date; // yyyy-MM-dd
    private int registerCount;
    private int activeCount;
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public int getRegisterCount() {
        return registerCount;
    }
    public void setRegisterCount(int registerCount) {
        this.registerCount = registerCount;
    }
    public int getActiveCount() {
        return activeCount;
    }
    public void setActiveCount(int activeCount) {
        this.activeCount = activeCount;
    }

    @Override
    public String toString() {
        return "Stat{" +
                "date='" + date + '\'' +
                ", registerCount=" + registerCount +
                ", activeCount=" + activeCount +
                '}';
    }
}
